import xlrd
import weichat.beforeLoadModel
from wzusxjm.models import Member, Activity

load = True
test = False

if load:
    data = xlrd.open_workbook('data.xls')
    table = data.sheet_by_index(0)
    for i in range(1, table.nrows):
        new_m = Member()
        new_m.name = table.cell(i, 0).value
        if table.cell(i, 2).value:
            new_m.SNO = str(int(table.cell(i, 2).value))
            new_m.college = table.cell(i, 3).value
            new_m.major = table.cell(i, 4).value
            new_m.sex = table.cell(i, 5).value
            if table.cell(i, 7).value:
                new_m.phone = str(int(table.cell(i, 7).value))
            new_m.category = table.cell(i, 8).value
            new_m.OpenID = ''
            new_m.addition = ''
            new_m.save()
        else:
            print('{}:{}'.format(new_m.name, new_m.SNO))

if test:
    activity = Activity.objects.first()
    activity.fresh()
